<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.w3.org/2000/svg"
	xmlns:svg="http://www.w3.org/2000/svg"
	xmlns:dg="livcos.org/ns/doc/diagram"
	xmlns:xlink="http://www.w3.org/1999/xlink"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:f="livcos.org/ns/xslt/function"
	exclude-result-prefixes="dg f xs svg xlink">
	
	<xsl:import href="render.xsl"/>
	
	<xsl:param name="ref"/>
	
	<xsl:output method="xml" media-type="image/svg+xml"/>

	<xsl:template match="/">
		<xsl:variable name="_objId" select="f:find-data-object($ref)"/>
		<xsl:choose>
			<xsl:when test="not($ref)">
				<xsl:apply-templates select="dg:diagram[1]"/>
			</xsl:when>
			<xsl:when test="$_objId != ''">
				<xsl:apply-templates select="doc($_objId)//dg:diagram[1]"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:sequence select="doc(concat('/livcos.org/web/sys/feedback/ObjectNotFound?objUri=', $ref))/*"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
</xsl:stylesheet>